/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dataobject.SemesterDO;
import org.xstgongyi.eduaid.manager.SemesterManager;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author oldcrane
 * @created 2019-04-02
 */
@Service
public class SemesterServiceImpl implements SemesterService {

    @Autowired
    private SemesterManager semesterManager;

    @Override
    public void insert(String name, Integer schoolYearId, Boolean active) {
        // TODO 此处需要增加逻辑，检查name是否重复
        // TODO 需要增加异常处理逻辑
        SemesterDO semesterDO = new SemesterDO();
        semesterDO.setName(name);
        semesterDO.setSchoolYearId(schoolYearId);
        semesterDO.setActive(active);
        LocalDateTime now = LocalDateTime.now();
        semesterDO.setGmtCreated(now);
        semesterDO.setGmtUpdated(now);
        semesterManager.insert(semesterDO);
    }

    @Override
    public void update(Integer id, String name, Integer schoolYearId, Boolean active) {
        // TODO 此处需要增加逻辑，检查name是否重复
        // TODO 需要增加异常处理逻辑
        SemesterDO semesterDO = new SemesterDO();
        semesterDO.setId(id);
        semesterDO.setName(name);
        semesterDO.setSchoolYearId(schoolYearId);
        semesterDO.setActive(active);
        semesterDO.setGmtUpdated(LocalDateTime.now());
        semesterManager.update(semesterDO);
    }

    @Override
    public List<SemesterDO> listAll() {
        return semesterManager.listAll();
    }

    @Override
    public List<SemesterDO> listByStatus(Boolean active) {
        return semesterManager.listAllByStatus(active);
    }

    @Override
    public SemesterDO getById(Integer id) {
        return semesterManager.getById(id);
    }

}
